import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'
    hide RefreshIndicator, RefreshIndicatorState;
import '../internals/indicator_wrap.dart';
import '../smart_refresher.dart';

class ClassicHeader extends RefreshIndicator {
  const ClassicHeader({super.key, required this.iconColor});

  final Color iconColor;

  @override
  State createState() => _ClassicHeaderState();
}

class _ClassicHeaderState extends RefreshIndicatorState<ClassicHeader> {
  Widget _buildIcon(mode) {
    final Widget icon = AnimatedRotation(
        duration: const Duration(milliseconds: 250),
        curve: Curves.fastOutSlowIn,
        turns: mode == RefreshStatus.idle ? 0 : 0.5,
        child: mode == RefreshStatus.canRefresh || mode == RefreshStatus.idle
            ? Icon(Icons.arrow_downward, color: widget.iconColor)
            : mode == RefreshStatus.refreshing
                ? const SizedBox(
                    width: 25.0,
                    height: 25.0,
                    child: CupertinoActivityIndicator())
                : const SizedBox.shrink());
    return icon;
  }

  @override
  bool needReverseAll() {
    return false;
  }

  @override
  Widget buildContent(BuildContext context, RefreshStatus? mode) {
    final Widget iconWidget = _buildIcon(mode);
    return SizedBox(height: widget.height, child: iconWidget);
  }
}
